// 智能锁列表
import debounce from "debounce";
import * as MSroomAPI from "../../api/interfaces/MSroom";
import { HttpHandler } from "../../api/handle/httpHandler";
import { AES_Encrypt } from "../../utils/crypto";

Page({
  data: {
    roomList: [],

  },
  onLoad() {


    // console.log(opt.hotelId);
  },

  onShow() {


    const eventChannel = this.getOpenerEventChannel();
    this.eventChannel = eventChannel
    eventChannel.on('hotelInfo', (data) => {
      this.setData({ hotelInfo: data.item });
      this.getRoomList(data.item.id)
    });

  },
  // 获取房间
  getRoomList(hotelId) {
    MSroomAPI.getRoomByHotelId({
      hotelId: hotelId
    }).then(res => {
      if (res.result) {
        let demo = res.result.records
        demo.forEach(e => {
          if(e.cover){
            e.cover = 'https://lyms.imsdx.net/lyms/' + e.cover.split(',')[0]

          }
        });
        this.setData({ roomList: res.result.records });
      }
    })
  },
  // 进入酒店详情
  toDetail(e) {

    
    if (!wx.getStorageSync('token')) {
       wx.navigateTo({
          url: '/pages/userLogin/userLogin'
        }
      )
    }else {
   wx.navigateTo({
      url: "../list/list",
      success: function (res) {
        // 通过eventChannel向被打开页面传送数据
        res.eventChannel.emit('roomInfo', {
          item: e.currentTarget.dataset.query,

        })
      }
    })
    }
 
  },


  /* TODO 处理用户错误日志, 用户可自行操作日志上传 */
  handleShowLog(...args: any) {
    console.log("操作日志:", ...args);
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    // this.modifyKeyList();
  },

  onReachBottom() {
    // this.modifyKeyList(this.data.currentPageNo + 1);
  },







})